<template>
  <div class="container">
    <!-- 预览功能的对话框 -->
    <el-dialog title="提示" @close="off" :visible="dialogVisible" width="50%">
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="6">【题型】:{{ form.questionType | question }}</el-col>
          <el-col :span="6">【编号】:{{ form.id }}</el-col>
          <el-col :span="6">【难度】:{{ form.difficulty | dif }}</el-col>
          <el-col :span="6">【标签】：{{ form.tags }}</el-col>
        </el-row>
        <el-row>
          <el-col :span="6">【学科】:{{ form.subjectName }}</el-col>
          <el-col :span="6">【目录】:{{ form.directoryName }}</el-col>
          <el-col :span="6">【方向】:{{ form.direction }}</el-col>
        </el-row>
        <el-row>
          <el-col :span="24">【题干】:{{ form.question | html2Text }} </el-col>
          <!-- 题型是简答时显示对应答案 -->
          <el-col v-if="form.questionType == '3'" :span="24"> {{ form.question | html2Text }}</el-col>
          <el-col :span="24">
            <div v-for="item in form.options" :key="item.code">
              <!-- 题型是单选时显示对应答案 -->
              <el-radio v-if="form.questionType == '1'" :value="item.isRight" :label="1">{{ item.title }}</el-radio>
              <!-- 题型是多选时显示对应答案 -->
              <!-- isRight如果是true则选中 -->
              <el-checkbox v-if="form.questionType == '2'" :value="item.isRight ? true : false">{{
                item.title
              }}</el-checkbox>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">【参考答案】:<el-button type="danger" @click="videoBtn">视频答案预览</el-button></el-col>
        </el-row>
        <el-row>
          <el-col :span="24">【答案解析】</el-col>
          <el-col :span="24">{{ form.answer | html2Text }}</el-col>
          <el-col :span="24">
            <div v-show="show">
              <!-- controls(自动播放) loop（循环播放）mutd (静音播放) -->
              <!-- 如果无视频连接，不打开播放器即可。 -->
              <video v-if="form.videoURL" :src="form.videoURL" controls ref="myvideo"></video>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">【题目备注】:{{ form.remarks }}</el-col>
          <el-col :span="12"></el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="success" @click="off">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    return {
      form: {},
      show: false,
      timer: null
    }
  },
  props: ['dialogVisible'],
  methods: {
    off () {
      this.$emit('update:dialogVisible', false)
      this.show = false
      clearInterval(this.timer)
    },
    // 点击按钮时显示视频
    videoBtn () {
      this.show = true
      // this.$refs.myvideo.play()
    }
  },
  mouted () {
    this.timer = setInterval(() => {
      // 要执行的函数
      this.$refs.myvideo.play()
    }, 500)
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-row {
  margin-top: 20px;
  padding: 15px;
  border-bottom: 1px gray solid;
}
.status {
  margin: 20px;
}
</style>
